Quant Bootcamp

Sahil Deo and Jayati Sharma

About CPC

A Little About You

  • Your name
  • Your profession
  • Have you learnt any programming language/coded before?
  • Anything more you would like to share :)

Why Quant Bootcamp?

Why R? - The power of R

Opening R

  • This is what your RStudio screen looks like

Source : University of Melbourne

Objects in R

  • The most common type of object in R is vector

  • Vectors can store all types of data: integers, characters, logical

id <- c(1,2,3,4,5)
id
[1] 1 2 3 4 5
  • Similarly, another vector with characters can be made
name <- c("John", "Mary", "Cal", "Jess","Sam")
name
[1] "John" "Mary" "Cal"  "Jess" "Sam" 

Objects in R

  • Factor object encodes a vector of unique elements into levels
score <- c("Very Bad", "Bad", "Neutral", "Good","Very Good")
print(factor(score))
[1] Very Bad  Bad       Neutral   Good      Very Good
Levels: Bad Good Neutral Very Bad Very Good
  • Can you try making a vector called age with 5 values?
age <- c(19, 21, 15, 25,23)
age
[1] 19 21 15 25 23

Objects in R

  • Dataframes are tabular data objects
  • Each column in a dataframe is a vector
  • You can create a dataframe using the vectors you just created
dataframe1 <- data.frame(id, name, score, age)
dataframe1
  id name     score age
1  1 John  Very Bad  19
2  2 Mary       Bad  21
3  3  Cal   Neutral  15
4  4 Jess      Good  25
5  5  Sam Very Good  23

R Projects

Content for this topic has been sourced from Danielle Navarro’s workshop. Please check out her work for detailed information.

What?

  • For organising files in a project
  • A tool to track your project

In their own words, RStudio projects make it straightforward to divide your work into multiple contexts, each with their own working directory, workspace, history, and source documents

Why

  • Although R keeps track of various different events that have happened but it has no idea which events are associated with particular project

  • Convenience

    • Keeps things tidy and smooths the process
  • Functionality

    • An RStudio project creates a .Rproj file that links the different scripts, data sets, etc within a particular folder on your computer
    • Also makes it easier to share code with others

R Projects

Content for this topic has been sourced from Danielle Navarro’s workshop. Please check out her work for detailed information.

How?

Go to the the little blue menu in the top the top right corner in RStudio, click on the dropdown menu, and select ‘New Project’

You can either:

  • Choose to open a project in a new directory
  • Or choose to work in an existing directory

Once you’ve created the project, if you have a look at the folder in Windows Explorer / Mac Finder in the respective directory, you’ll see your file!

Packages and Libraries

  • When using R, you will be writing functions to perform operations
  • Essentially, a package is a collection of functions
  • You need to install a package only once using install.package
  • However, you need to load it every session

Source: Allison Horst

Data Wrangling in R

What?

Why?

How?

Pipe Operators in R